home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / comm / yep16.zip / YEPU.ZIP / YEPUMAX.CMD < prev    next >
OS/2 REXX Batch file  |  1996-11-12  |  3KB  |  101 lines

  1. /* YEPuMAX - Trim Yep URL Log to the most recent X number of entries
  2.  
  3.  - please edit the line below to reflect the path/filename of your Log,
  4.    or specify filename on command line. I.E. YEPuMAX url.log >my-new.log
  5.  - please edit the variable below for the default maximum number of URLs
  6.    to keep, or specify as -second- command line parameter.
  7.    I.E. YEPuMAX url.log 50
  8.  - The Url Log will be backed up and then overwritten with the new Url Log.   
  9.    
  10. */
  11.  
  12. UrlLog = 'd:\tm\url.log'
  13. UrlLogBackup = 'd:\tm\url.bak'
  14. Keep = 100
  15.  
  16.  
  17. /* don't touch theses */
  18. BetweenRecords = 1;
  19. UrlNum = 0
  20. URLS. = ''
  21. All. = ''
  22. Records = 0
  23.  
  24. Parse arg ln cKeep
  25. if (ln \= '') then UrlLog = ln
  26. if (cKeep > 0) then Keep = cKeep
  27.  
  28. ret = stream(UrlLog,'c','open read')
  29. if ret <> 'READY:' then do
  30.     say 'Can not open URL Log "'UrlLog'" to read.'
  31.     exit
  32. end
  33.  
  34. say 'Keeping only the 'keep' most recent urls in 'UrlLog'...'
  35.  
  36. /* suck in urls to stem -- with dupe elimination */
  37. do while lines(UrlLog)<>0
  38.     ln = linein(UrlLog)
  39.     if (ln \= '') & (BetweenRecords = 1) then do
  40.         BetweenRecords = 0;        
  41.         RecordLines = 0
  42.         Duplicate = 0
  43.         Records = Records + 1
  44.     end
  45.     
  46.     if (ln \= '') & (BetweenRecords = 0) & (duplicate = 0) then do
  47.         RecordLines = RecordLines + 1
  48.         Arecord.RecordLines = ln
  49.         if SubStr(ln,1,4) == 'URL:' then do
  50.             do x = 1 to UrlNum 
  51.                 if URLS.x = ln then Duplicate = 1
  52.             end
  53.             if Duplicate = 0 then do
  54.                 UrlNum = UrlNum + 1
  55.                 URLS.UrlNum = ln
  56.             end            
  57.         end
  58.     end
  59.     
  60.     if (ln == '') & (BetweenRecords = 0) then do
  61.         betweenRecords = 1;
  62.         if Duplicate = 0 then do
  63.             All.UrlNum.0 = RecordLines
  64.             do x = 1 to RecordLines 
  65.                 All.UrlNum.x = Arecord.x
  66.             end
  67.         end
  68.     end    
  69. end
  70. ret = stream(UrlLog,'c','close')
  71.  
  72. /* backup, delete, and output */
  73. '@copy '||UrlLog||' '||UrlLogBackUp||' >nul'
  74. '@del '||UrlLog||' >nul'
  75.  
  76. /* output */
  77. ret = stream(UrlLog,'c','open write');
  78. if ret = 'READY:' then do
  79.  
  80.     StartUrl = UrlNum - Keep + 1
  81.     if StartUrl < 1 then StartUrl = 1
  82.     if StartUrl > 0 then do
  83.         do x = StartUrl to UrlNum
  84.             do y = 1 to All.x.0
  85.                 ret = lineout(urlLog, All.x.y)
  86.             end
  87.             ret = lineout(urlLog, '')
  88.         end
  89.     end
  90.  
  91. end
  92. else do
  93.      say 'Warning: could not update '||UrlLog||'! Restoring backup.'
  94.      '@copy '||UrlLogBackup||' '||UrlLog||' >nul'
  95.      if rc = 0 then say 'Backup restored successfully.'
  96.      else say UrlLogBackUp||' could not be restored! You better look into it.'
  97. end
  98.  
  99. say 'Done processing 'UrlNum' Urls. ('keep' kept, 'StartUrl - 1' old urls trimmed)'
  100.  
  101.